package com.shanyi.common.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author shanyi
 * @create 2024-11-23-15:57
 */
public class BaiduWeatherUtil {

    private static final String URL = " https://api.map.baidu.com/weather/v1/";
    private static final String AK = "fCssWs9lGHtKDwmkoT4Uw6QafBZNsN9y";

    private static final Map<String, String> DISTRICT_ID = new HashMap<String, String>(){{
        put("杭州","330100");
        put("长春","220100");
    }};


    public static List<String> getWeather() {
        ArrayList<String> result = new ArrayList<>(DISTRICT_ID.size());
        for (Map.Entry<String, String> entry : DISTRICT_ID.entrySet()) {
            String url = buildUrl(entry.getValue());
            String response = OkHttpUtil.sendGetRequest(url);
            result.add(response);
        }
        return result;
    }


    public static String buildUrl(String districtId) {
        StringBuilder url = new StringBuilder();
        return url.append(URL).append("?district_id=").append(districtId)
                .append("&data_type=all&ak=").append(AK).toString();
    }

}
